﻿using System;
using System.Text;
using System.IO;
using System.Drawing;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Drawing.Text;

namespace SIGEB.Prototipo.Vista.UI
{
    public sealed class Fuente
    {
        [System.Runtime.InteropServices.DllImport("gdi32.dll")]
        private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont, IntPtr pdv, [System.Runtime.InteropServices.In] ref uint pcFonts);
        private static PrivateFontCollection MYpfc = new PrivateFontCollection();
        private readonly static Font fuente = new Font(inicializarFuente(), 8.25F);

        private static FontFamily inicializarFuente()
        {
            try
            {
                unsafe
                {
                    fixed (byte* pFontData = SIGEB.Prototipo.Properties.Resources.euphemia)
                    {
                        uint dummy = 0;
                        MYpfc.AddMemoryFont((IntPtr)pFontData, Properties.Resources.euphemia.Length);
                        AddFontMemResourceEx((IntPtr)pFontData, (uint)Properties.Resources.euphemia.Length, IntPtr.Zero, ref dummy);
                        return MYpfc.Families[0];
                    }
                }
            }
            catch
            {
                return new FontFamily(GenericFontFamilies.SansSerif);
            }
        }

        public static Font obtenerFuente()
        {
            return fuente;
        }

        public static Font obtenerFuente(float size)
        {
            return new Font(inicializarFuente(), size);
        }
    }
}
